<?php
require_once __DIR__ . '/../functions.php';

// 检查管理员权限
if (!isAdmin()) {
    redirect('../index.php', '您没有权限访问此页面', 'danger');
}

$db = getDB();

// 处理表单提交
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $action = $_POST['action'] ?? '';
    
    if ($action == 'add_announcement') {
        // 添加公告
        $title = $_POST['title'] ?? '';
        $content = $_POST['content'] ?? '';
        $priority = intval($_POST['priority'] ?? 0);
        $isActive = isset($_POST['is_active']) ? 1 : 0;
        
        // 处理图片上传
        $images = [];
        if (!empty($_FILES['images']['name'][0])) {
            foreach ($_FILES['images']['tmp_name'] as $key => $tmp_name) {
                if ($_FILES['images']['error'][$key] === UPLOAD_ERR_OK) {
                    $file = [
                        'name' => $_FILES['images']['name'][$key],
                        'type' => $_FILES['images']['type'][$key],
                        'tmp_name' => $tmp_name,
                        'error' => $_FILES['images']['error'][$key],
                        'size' => $_FILES['images']['size'][$key]
                    ];
                    
                    $uploadResult = uploadFile($file, 'image');
                    if ($uploadResult['success']) {
                        $images[] = [
                            'filename' => $uploadResult['filename'],
                            'url' => $uploadResult['url'],
                            'original_name' => $file['name']
                        ];
                    }
                }
            }
        }
        
        if (empty($title) || empty($content)) {
            $error = '请填写完整的公告信息';
        } else {
            $imagesJson = !empty($images) ? json_encode($images) : null;
            $stmt = $db->prepare("INSERT INTO announcements (title, content, images, priority, is_active) VALUES (?, ?, ?, ?, ?)");
            if ($stmt->execute([$title, $content, $imagesJson, $priority, $isActive])) {
                $success = '公告添加成功';
            } else {
                $error = '公告添加失败';
                // 删除已上传的图片
                foreach ($images as $image) {
                    deleteFile($image['filename'], 'image');
                }
            }
        }
    } elseif ($action == 'update_announcement') {
        // 更新公告
        $id = intval($_POST['id'] ?? 0);
        $title = $_POST['title'] ?? '';
        $content = $_POST['content'] ?? '';
        $priority = intval($_POST['priority'] ?? 0);
        $isActive = isset($_POST['is_active']) ? 1 : 0;
        $existingImages = $_POST['existing_images'] ?? [];
        
        // 获取现有图片
        $stmt = $db->prepare("SELECT images FROM announcements WHERE id = ?");
        $stmt->execute([$id]);
        $oldAnnouncement = $stmt->fetch();
        $oldImages = $oldAnnouncement && $oldAnnouncement['images'] ? json_decode($oldAnnouncement['images'], true) : [];
        
        // 处理新图片上传
        $newImages = [];
        if (!empty($_FILES['images']['name'][0])) {
            foreach ($_FILES['images']['tmp_name'] as $key => $tmp_name) {
                if ($_FILES['images']['error'][$key] === UPLOAD_ERR_OK) {
                    $file = [
                        'name' => $_FILES['images']['name'][$key],
                        'type' => $_FILES['images']['type'][$key],
                        'tmp_name' => $tmp_name,
                        'error' => $_FILES['images']['error'][$key],
                        'size' => $_FILES['images']['size'][$key]
                    ];
                    
                    $uploadResult = uploadFile($file, 'image');
                    if ($uploadResult['success']) {
                        $newImages[] = [
                            'filename' => $uploadResult['filename'],
                            'url' => $uploadResult['url'],
                            'original_name' => $file['name']
                        ];
                    }
                }
            }
        }
        
        // 合并图片：保留的现有图片 + 新上传的图片
        $finalImages = [];
        
        // 保留选中的现有图片
        if (!empty($existingImages) && !empty($oldImages)) {
            foreach ($oldImages as $oldImage) {
                if (in_array($oldImage['filename'], $existingImages)) {
                    $finalImages[] = $oldImage;
                } else {
                    // 删除被移除的图片
                    deleteFile($oldImage['filename'], 'image');
                }
            }
        } elseif (!empty($oldImages)) {
            // 如果没有选择保留任何现有图片，删除所有旧图片
            foreach ($oldImages as $oldImage) {
                deleteFile($oldImage['filename'], 'image');
            }
        }
        
        // 添加新上传的图片
        $finalImages = array_merge($finalImages, $newImages);
        $imagesJson = !empty($finalImages) ? json_encode($finalImages) : null;
        
        if ($id <= 0 || empty($title) || empty($content)) {
            $error = '请填写完整的公告信息';
        } else {
            $stmt = $db->prepare("UPDATE announcements SET title = ?, content = ?, images = ?, priority = ?, is_active = ?, updated_at = NOW() WHERE id = ?");
            if ($stmt->execute([$title, $content, $imagesJson, $priority, $isActive, $id])) {
                $success = '公告更新成功';
            } else {
                $error = '公告更新失败';
                // 删除新上传的图片
                foreach ($newImages as $image) {
                    deleteFile($image['filename'], 'image');
                }
            }
        }
    } elseif ($action == 'delete_announcement') {
        // 删除公告
        $id = intval($_POST['id'] ?? 0);
        
        if ($id <= 0) {
            $error = '公告ID无效';
        } else {
            // 先获取图片信息
            $stmt = $db->prepare("SELECT images FROM announcements WHERE id = ?");
            $stmt->execute([$id]);
            $announcement = $stmt->fetch();
            
            // 删除图片文件
            if ($announcement && $announcement['images']) {
                $images = json_decode($announcement['images'], true);
                foreach ($images as $image) {
                    deleteFile($image['filename'], 'image');
                }
            }
            
            $stmt = $db->prepare("DELETE FROM announcements WHERE id = ?");
            if ($stmt->execute([$id])) {
                $success = '公告删除成功';
            } else {
                $error = '公告删除失败';
            }
        }
    }
}

// 获取公告列表
$stmt = $db->query("SELECT * FROM announcements ORDER BY priority DESC, created_at DESC");
$announcements = $stmt->fetchAll();

include __DIR__ . '/header.php';
?>

            <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
                <h1 class="h2">公告管理</h1>
                <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addAnnouncementModal">
                    <i class="bi bi-plus-circle"></i> 发布公告
                </button>
            </div>

            <?php if (isset($error)): ?>
                <div class="alert alert-danger alert-dismissible fade show" role="alert">
                    <i class="bi bi-exclamation-triangle-fill"></i> <?php echo htmlspecialchars($error); ?>
                    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                </div>
            <?php endif; ?>
            
            <?php if (isset($success)): ?>
                <div class="alert alert-success alert-dismissible fade show" role="alert">
                    <i class="bi bi-check-circle-fill"></i> <?php echo htmlspecialchars($success); ?>
                    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                </div>
            <?php endif; ?>

            <!-- 统计信息 -->
            <div class="row mb-4">
                <div class="col-md-3">
                    <div class="card bg-primary text-white">
                        <div class="card-body text-center">
                            <h5 class="card-title">
                                <i class="bi bi-megaphone"></i> 总公告数
                            </h5>
                            <h3 class="mb-0"><?php echo count($announcements); ?></h3>
                        </div>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="card bg-success text-white">
                        <div class="card-body text-center">
                            <h5 class="card-title">
                                <i class="bi bi-check-circle"></i> 已启用
                            </h5>
                            <?php
                            $activeCount = count(array_filter($announcements, function($a) { return $a['is_active']; }));
                            ?>
                            <h3 class="mb-0"><?php echo $activeCount; ?></h3>
                        </div>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="card bg-warning text-white">
                        <div class="card-body text-center">
                            <h5 class="card-title">
                                <i class="bi bi-pause-circle"></i> 已禁用
                            </h5>
                            <h3 class="mb-0"><?php echo count($announcements) - $activeCount; ?></h3>
                        </div>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="card bg-danger text-white">
                        <div class="card-body text-center">
                            <h5 class="card-title">
                                <i class="bi bi-exclamation-triangle"></i> 重要公告
                            </h5>
                            <?php
                            $importantCount = count(array_filter($announcements, function($a) { return $a['priority'] > 0; }));
                            ?>
                            <h3 class="mb-0"><?php echo $importantCount; ?></h3>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 公告列表 -->
            <div class="card">
                <div class="card-header bg-primary text-white">
                    <h5 class="mb-0">
                        <i class="bi bi-list"></i> 公告列表
                        <span class="badge bg-light text-primary ms-2"><?php echo count($announcements); ?></span>
                    </h5>
                </div>
                <div class="card-body">
                    <?php if (empty($announcements)): ?>
                        <div class="text-center text-muted py-5">
                            <i class="bi bi-inbox display-1"></i>
                            <h4 class="mt-3">暂无公告</h4>
                            <p class="text-muted">还没有发布任何公告</p>
                            <button type="button" class="btn btn-primary mt-3" data-bs-toggle="modal" data-bs-target="#addAnnouncementModal">
                                <i class="bi bi-plus-circle"></i> 发布第一个公告
                            </button>
                        </div>
                    <?php else: ?>
                        <div class="table-responsive">
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>标题</th>
                                        <th>内容</th>
                                        <th>图片</th>
                                        <th>优先级</th>
                                        <th>状态</th>
                                        <th>创建时间</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php foreach ($announcements as $announcement): ?>
                                        <tr>
                                            <td><?php echo $announcement['id']; ?></td>
                                            <td>
                                                <strong><?php echo htmlspecialchars($announcement['title']); ?></strong>
                                                <?php if ($announcement['priority'] > 0): ?>
                                                    <span class="badge bg-danger ms-1">重要</span>
                                                <?php endif; ?>
                                            </td>
                                            <td>
                                                <div class="text-truncate" style="max-width: 300px;">
                                                    <?php echo nl2br(htmlspecialchars($announcement['content'])); ?>
                                                </div>
                                            </td>
                                            <td>
                                                <?php if ($announcement['images']): ?>
                                                    <?php 
                                                    $images = json_decode($announcement['images'], true);
                                                    $imageCount = count($images);
                                                    ?>
                                                    <span class="badge bg-info">
                                                        <i class="bi bi-image"></i> <?php echo $imageCount; ?>张
                                                    </span>
                                                <?php else: ?>
                                                    <span class="text-muted">无图片</span>
                                                <?php endif; ?>
                                            </td>
                                            <td>
                                                <span class="badge bg-<?php echo $announcement['priority'] > 0 ? 'danger' : 'secondary'; ?>">
                                                    <?php echo $announcement['priority']; ?>
                                                </span>
                                            </td>
                                            <td>
                                                <span class="badge bg-<?php echo $announcement['is_active'] ? 'success' : 'secondary'; ?>">
                                                    <?php echo $announcement['is_active'] ? '启用' : '禁用'; ?>
                                                </span>
                                            </td>
                                            <td><?php echo date('Y-m-d H:i', strtotime($announcement['created_at'])); ?></td>
                                            <td>
                                                <div class="btn-group" role="group">
                                                    <button type="button" class="btn btn-sm btn-outline-primary edit-btn"
                                                            data-id="<?php echo $announcement['id']; ?>"
                                                            data-title="<?php echo htmlspecialchars($announcement['title']); ?>"
                                                            data-content="<?php echo htmlspecialchars($announcement['content']); ?>"
                                                            data-priority="<?php echo $announcement['priority']; ?>"
                                                            data-is-active="<?php echo $announcement['is_active']; ?>"
                                                            data-images='<?php echo $announcement['images'] ? htmlspecialchars($announcement['images'], ENT_QUOTES) : ''; ?>'
                                                            data-bs-toggle="tooltip" title="编辑">
                                                        <i class="bi bi-pencil"></i>
                                                    </button>
                                                    <form method="POST" style="display: inline;" 
                                                          onsubmit="return confirm('确定要删除这个公告吗？');">
                                                        <input type="hidden" name="action" value="delete_announcement">
                                                        <input type="hidden" name="id" value="<?php echo $announcement['id']; ?>">
                                                        <button type="submit" class="btn btn-sm btn-outline-danger" 
                                                                data-bs-toggle="tooltip" title="删除">
                                                            <i class="bi bi-trash"></i>
                                                        </button>
                                                    </form>
                                                </div>
                                            </td>
                                        </tr>
                                    <?php endforeach; ?>
                                </tbody>
                            </table>
                        </div>
                    <?php endif; ?>
                </div>
            </div>

<!-- 添加公告模态框 -->
<div class="modal fade" id="addAnnouncementModal" tabindex="-1">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">发布公告</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body">
                <form method="POST" id="addAnnouncementForm" enctype="multipart/form-data">
                    <input type="hidden" name="action" value="add_announcement">
                    
                    <div class="mb-3">
                        <label for="title" class="form-label">公告标题 <span class="text-danger">*</span></label>
                        <input type="text" class="form-control" id="title" name="title" 
                               placeholder="请输入公告标题" required>
                    </div>
                    
                    <div class="mb-3">
                        <label for="content" class="form-label">公告内容 <span class="text-danger">*</span></label>
                        <textarea class="form-control" id="content" name="content" rows="6" 
                                  placeholder="请输入公告内容" required></textarea>
                    </div>

                    <!-- 图片上传区域 -->
                    <div class="mb-3">
                        <label for="images" class="form-label">公告图片</label>
                        <input type="file" class="form-control" id="images" name="images[]" 
                               multiple accept="image/*" onchange="previewImages(this, 'addPreview')">
                        <div class="form-text">支持多张图片上传，单张图片最大5MB</div>
                        
                        <div id="addPreview" class="image-preview mt-3 row g-2"></div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="priority" class="form-label">优先级</label>
                                <select class="form-select" id="priority" name="priority">
                                    <option value="0">普通</option>
                                    <option value="1">重要</option>
                                    <option value="2">紧急</option>
                                    <option value="3">置顶</option>
                                </select>
                                <div class="form-text">优先级越高，公告显示越靠前</div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label">状态</label>
                                <div class="form-check form-switch">
                                    <input class="form-check-input" type="checkbox" id="is_active" name="is_active" value="1" checked>
                                    <label class="form-check-label" for="is_active">
                                        立即启用公告
                                    </label>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" onclick="submitAddForm()">
                    <i class="bi bi-send-fill"></i> 发布公告
                </button>
            </div>
        </div>
    </div>
</div>

<!-- 编辑公告模态框 -->
<div class="modal fade" id="editAnnouncementModal" tabindex="-1">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">编辑公告</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body">
                <form method="POST" id="editAnnouncementForm" enctype="multipart/form-data">
                    <input type="hidden" name="action" value="update_announcement">
                    <input type="hidden" name="id" id="edit_id">
                    
                    <div class="mb-3">
                        <label for="edit_title" class="form-label">公告标题 <span class="text-danger">*</span></label>
                        <input type="text" class="form-control" id="edit_title" name="title" required>
                    </div>
                    
                    <div class="mb-3">
                        <label for="edit_content" class="form-label">公告内容 <span class="text-danger">*</span></label>
                        <textarea class="form-control" id="edit_content" name="content" rows="6" required></textarea>
                    </div>

                    <!-- 图片上传区域 -->
                    <div class="mb-3">
                        <label for="edit_images" class="form-label">公告图片</label>
                        <input type="file" class="form-control" id="edit_images" name="images[]" 
                               multiple accept="image/*" onchange="previewImages(this, 'editPreview')">
                        <div class="form-text">支持多张图片上传，单张图片最大5MB</div>
                        
                        <div id="editPreview" class="image-preview mt-3 row g-2"></div>
                        <div id="existingImages" class="existing-images mt-2"></div>
                    </div>
                    
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="edit_priority" class="form-label">优先级</label>
                                <select class="form-select" id="edit_priority" name="priority">
                                    <option value="0">普通</option>
                                    <option value="1">重要</option>
                                    <option value="2">紧急</option>
                                    <option value="3">置顶</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label">状态</label>
                                <div class="form-check form-switch">
                                    <input class="form-check-input" type="checkbox" id="edit_is_active" name="is_active" value="1">
                                    <label class="form-check-label" for="edit_is_active">
                                        启用公告
                                    </label>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" onclick="submitEditForm()">
                    <i class="bi bi-save"></i> 保存修改
                </button>
            </div>
        </div>
    </div>
</div>

<!-- 图片查看模态框 -->
<div class="modal fade" id="imageViewerModal" tabindex="-1">
    <div class="modal-dialog modal-xl">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">图片预览</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body text-center">
                <img id="viewerImage" src="" class="img-fluid" style="max-height: 80vh;">
            </div>
        </div>
    </div>
</div>
<?php include __DIR__ . '/footer.php'; ?>
<script>
// 图片预览功能
function previewImages(input, previewId) {
    const preview = document.getElementById(previewId);
    preview.innerHTML = '';
    
    if (input.files && input.files.length > 0) {
        for (let i = 0; i < input.files.length; i++) {
            const file = input.files[i];
            const reader = new FileReader();
            
            reader.onload = function(e) {
                const col = document.createElement('div');
                col.className = 'col-6 col-md-4 col-lg-3';
                col.innerHTML = `
                    <div class="image-item position-relative">
                        <img src="${e.target.result}" class="img-thumbnail w-100" style="height: 100px; object-fit: cover;">
                        <button type="button" class="btn btn-sm btn-danger position-absolute top-0 end-0" 
                                onclick="removeImagePreview(this)">
                            <i class="bi bi-x"></i>
                        </button>
                    </div>
                `;
                preview.appendChild(col);
            }
            
            reader.readAsDataURL(file);
        }
    }
}

// 移除图片预览
function removeImagePreview(button) {
    const imageItem = button.closest('.col-6');
    imageItem.remove();
}

// 查看图片
function viewImage(url) {
    document.getElementById('viewerImage').src = url;
    const modal = new bootstrap.Modal(document.getElementById('imageViewerModal'));
    modal.show();
}

// 编辑公告时加载现有图片
function editAnnouncement(id, title, content, priority, isActive, imagesJson) {
    document.getElementById('edit_id').value = id;
    document.getElementById('edit_title').value = title;
    document.getElementById('edit_content').value = content;
    document.getElementById('edit_priority').value = priority;
    document.getElementById('edit_is_active').checked = isActive;
    
    // 清空预览
    document.getElementById('editPreview').innerHTML = '';
    const existingImagesContainer = document.getElementById('existingImages');
    existingImagesContainer.innerHTML = '';
    
    // 显示现有图片
    if (imagesJson && imagesJson.trim() !== '') {
        try {
            const imageList = JSON.parse(imagesJson);
            if (imageList && imageList.length > 0) {
                existingImagesContainer.innerHTML = '<h6 class="mb-2 text-muted">现有图片：</h6><div class="row g-2" id="existingImagesList">';
                
                imageList.forEach((image, index) => {
                    if (image && image.url) {
                        existingImagesContainer.querySelector('#existingImagesList').innerHTML += `
                            <div class="col-6 col-md-4 col-lg-3">
                                <div class="image-item position-relative">
                                    <img src="${image.url}" class="img-thumbnail w-100" 
                                         style="height: 100px; object-fit: cover; cursor: pointer;"
                                         onclick="viewImage('${image.url}')">
                                    <div class="form-check position-absolute top-0 start-0 m-1">
                                        <input class="form-check-input existing-image-checkbox" type="checkbox" 
                                               name="existing_images[]" value="${image.filename}" 
                                               id="img_${id}_${index}" checked>
                                        <label class="form-check-label text-white" for="img_${id}_${index}" 
                                               style="text-shadow: 1px 1px 2px rgba(0,0,0,0.8);">
                                            保留
                                        </label>
                                    </div>
                                    <button type="button" class="btn btn-sm btn-danger position-absolute top-0 end-0" 
                                            onclick="removeExistingImage(this, '${image.filename}')">
                                        <i class="bi bi-trash"></i>
                                    </button>
                                </div>
                            </div>
                        `;
                    }
                });
                
                existingImagesContainer.innerHTML += '</div>';
            } else {
                existingImagesContainer.innerHTML = '<p class="text-muted">暂无图片</p>';
            }
        } catch (error) {
            console.error('解析图片数据失败:', error);
            existingImagesContainer.innerHTML = '<p class="text-danger">图片数据解析失败</p>';
        }
    } else {
        existingImagesContainer.innerHTML = '<p class="text-muted">暂无图片</p>';
    }
    
    const modal = new bootstrap.Modal(document.getElementById('editAnnouncementModal'));
    modal.show();
}

// 移除现有图片（标记为不保留）
function removeExistingImage(button, filename) {
    const imageItem = button.closest('.col-6');
    const checkbox = imageItem.querySelector('.existing-image-checkbox');
    if (checkbox) {
        checkbox.checked = false;
    }
    imageItem.style.opacity = '0.5';
    imageItem.style.transform = 'scale(0.95)';
    
    // 3秒后移除动画效果，但保持半透明状态
    setTimeout(() => {
        imageItem.style.transform = 'scale(1)';
    }, 300);
}

function submitAddForm() {
    const form = document.getElementById('addAnnouncementForm');
    if (form.checkValidity()) {
        form.submit();
    } else {
        form.classList.add('was-validated');
    }
}

function submitEditForm() {
    const form = document.getElementById('editAnnouncementForm');
    if (form.checkValidity()) {
        form.submit();
    } else {
        form.classList.add('was-validated');
    }
}

// 为编辑按钮添加事件监听器
document.addEventListener('DOMContentLoaded', function() {
    const editButtons = document.querySelectorAll('.edit-btn');
    editButtons.forEach(button => {
        button.addEventListener('click', function() {
            const id = this.getAttribute('data-id');
            const title = this.getAttribute('data-title');
            const content = this.getAttribute('data-content');
            const priority = this.getAttribute('data-priority');
            const isActive = this.getAttribute('data-is-active');
            const imagesJson = this.getAttribute('data-images');
            
            editAnnouncement(id, title, content, priority, isActive, imagesJson);
        });
    });
});

// 初始化工具提示
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
    return new bootstrap.Tooltip(tooltipTriggerEl);
});
</script>

<style>
.image-preview, .existing-images {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 10px;
    background: #f8f9fa;
}

.image-item {
    transition: all 0.3s ease;
    border-radius: 6px;
    overflow: hidden;
}

.image-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.image-item img {
    cursor: pointer;
    transition: all 0.3s ease;
}

.image-item:hover img {
    transform: scale(1.05);
}

.image-item .btn {
    opacity: 0.8;
    transition: opacity 0.3s ease;
}

.image-item:hover .btn {
    opacity: 1;
}

/* 图片查看模态框样式 */
#imageViewerModal .modal-content {
    background: rgba(0,0,0,0.9);
    border: none;
}

#imageViewerModal .modal-header {
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

#imageViewerModal .modal-title {
    color: white;
}

#imageViewerModal .btn-close {
    filter: invert(1);
}

.existing-image-checkbox:checked + label {
    color: #28a745 !important;
}

/* 过渡动画 */
.transition-all {
    transition: all 0.3s ease;
}

/* 公告图片悬停效果 */
.announcement-image .image-overlay {
    transition: all 0.3s ease;
}

.announcement-image:hover .image-overlay {
    opacity: 1 !important;
}
</style>

